package com.bh.weapp.controller.sysuser.shipment;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.SecurityUtils;
import com.bh.shipment.domain.JcBerthStand;
import com.bh.shipment.domain.JcShipment;
import com.bh.shipment.domain.JcShipmentTrack;
import com.bh.shipment.service.IJcShipmentService;
import com.bh.shipment.service.IJcShipmentTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 运单追踪Controller
 *
 * @author slx
 * @date 2023-04-22
 */
@Api(tags = {"SYS运单在途追踪"})
@RestController
@RequestMapping("/api/sysuser/shipment/shipmentTrack")
public class JcShipmentTrackSysApiController extends BaseController {

    @Autowired
    private IJcShipmentTrackService jcShipmentTrackService;
    @Autowired
    private IJcShipmentService jcShipmentService;

    /**
     * 查询运单追踪列表
     */
    @PreAuthorize("@ss.hasPermi('api:shipment:track:list')")
    @ApiOperation("查询运单追踪列表")
    @GetMapping("/getTrackByShipmentId/{jcShipmentId}")
    public AjaxResult getTrackByShipmentId(@PathVariable("jcShipmentId") Long jcShipmentId) {
        JcShipmentTrack jcShipmentTrac = new JcShipmentTrack();
        jcShipmentTrac.setJcShipmentId(jcShipmentId);
        List<JcShipmentTrack> list = jcShipmentTrackService.selectJcShipmentTrackList(jcShipmentTrac);
        return AjaxResult.success(list);
    }

    /**
     * 新增保存运单追踪
     */
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation("新增保存运单追踪")
    @PreAuthorize("@ss.hasPermi('api:shipment:track:add')")
    @Log(title = "运单追踪", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody JcShipmentTrack jcShipmentTrack) {
        jcShipmentTrack.setType(0);
        jcShipmentTrack.setPerson(SecurityUtils.getUsername());
        jcShipmentTrack.setTime(new Date());
        return toAjax(jcShipmentTrackService.insertJcShipmentTrack(jcShipmentTrack));
    }
}
